# -*- coding: utf-8 -*-
import scrapy
from itcast.items import ItcastItem

class DemoSpider(scrapy.Spider):
    # 启动的名字
    name = 'demo'
    # 获取数据的范围
    allowed_domains = ['itcast.cn']
    # 数据的url
    start_urls = ['http://www.itcast.cn/channel/teacher.shtml#ac']

    def parse(self, response):
        # 取出要获取的xpath
        div_list = response.xpath('//div[@class="tea_con"]/div[1]//div[@class="li_txt"]')

        for div in div_list:
            # 导入限制字段 确报不会写错字段
            dict_data = ItcastItem()
            # 姓名
            dict_data['name'] = div.xpath('./h3/text()')[0].extract()
            # 职称
            dict_data['position'] = div.xpath('./h4/text()')[0].extract()
            # 介绍
            dict_data['info'] = div.xpath('./p/text()')[0].extract()

            print('*' * 50)
            print(dict_data)
            # 这里不能return 否则会只返回第一个
            yield dict_data






